package com.jt.controller;

import com.jt.pojo.Customer;
import com.jt.service.CustomerService;
import com.jt.vo.PageResult;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    //客户列表展现
    @GetMapping("/getCustomerList")
    public SysResult getCustomerList(PageResult pageResult){
        pageResult = customerService.getCustomerList(pageResult);
        return SysResult.success(pageResult);
    }

    //新增客户
    @PostMapping("/addCustomer")
    public SysResult addCustomer(@RequestBody Customer customer){
        customerService.addCustomer(customer);
        return SysResult.success();
    }

    //客户信息修改
    @PutMapping("/updateCustomer")
    public SysResult updateCustomer(@RequestBody Customer customer){
        customerService.updateCustomer(customer);
        return SysResult.success();
    }

    //删除客户信息
    @DeleteMapping("/{id}")
    public SysResult deleteCustomer(@PathVariable Integer id){
        customerService.deleteCustomer(id);
        return SysResult.success();
    }

    @GetMapping("/{id}")
    public SysResult getCustomerMessage(@PathVariable Integer id){
        Customer customer = customerService.getCustomerMessage(id);
        return SysResult.success(customer);
    }
}
